package com.crm.service.statisticAnalysis.controller;

import com.crm.model.common.dtos.ResponseResult;
import com.crm.model.statisticAnalysis.dtos.ClientPageDTO;
import com.crm.service.statisticAnalysis.service.ClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.Date;

@RestController
@RequestMapping("/api/v1/statistics/client")
@Api("客户统计")
@Slf4j
public class ClientController {

    @Autowired
    private ClientService clientService;

    @ApiOperation("用户统计分页条件查询")
    @PostMapping("/clientPage")
    public ResponseResult clientPage(@RequestBody ClientPageDTO clientPageDTO) {
        log.info("用户统计分页条件查询:{}", clientPageDTO);
        return clientService.clientPage(clientPageDTO);
    }

    @ApiOperation("折线图")
    @GetMapping("/client_lineChart")
    public ResponseResult clientLineChart(
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end) {
        log.info("客户统计折线图{},{}",begin,end);
        return clientService.clientLineChart(begin,end);

    }

    @ApiOperation("环形图")
    @GetMapping("/client_doughnutChart")
    public ResponseResult doughnutChart(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate queryTime){
        log.info("客户统计环形图:{}",queryTime);
       return clientService.doughnutChart(queryTime);
    }

    @ApiOperation("报表导出")
    @GetMapping("/export")
    public ResponseResult export(HttpServletResponse response){
        log.info("导出客户统计报表>>>>>>>");
        return clientService.export(response);
    }

}
